﻿SmitearWebGL.Core.Geometry.Vertex = Class.extend(
{
	/******** constructor ********/
	
	init : function( x, y, z )
	{
		/******** public property ********/
		
		this.x = x || 0;
		this.y = y || 0;
		this.z = z || 0;
		
		this.normal = null;
		this.correlativeFaces = [];
		
		this._registClass( "SmitearWebGL.Core.Geometry.Vertex" );
	}
	,
	calculatNormal : function()
	{
		this.normal = $V3();
		
		var face;
		for ( var i = 0; i < this.correlativeFaces.length; ++ i )
		{
			face = this.correlativeFaces[i];
			this.normal.x += face.normal.x;
			this.normal.y += face.normal.y;
			this.normal.z += face.normal.z;
			
			this.normal.normalize();
		}
	}
	,
	release : function()
	{
		this.correlativeFaces = null;
		this.normal = null;
	}
	,
	compare : function( to )
	{
		return ( this.x == to.x && this.y == to.y && this.z == to.z );
	}
	,
	clone : function()
	{
		var newVertex = new SmitearWebGL.Core.Geometry.Vertex( this.x ,this.y, this.z );
		if ( this.normal )
		{
			newVertex.normal = this.normal.clone();
		}
		
		return newVertex;
	}
}
);